package com.framework;

import java.io.*;
import java.util.ArrayList;

import com.leff.midi.MidiFile;
import com.leff.midi.MidiTrack;
import com.leff.midi.event.NoteOff;
import com.leff.midi.event.NoteOn;
import com.leff.midi.event.meta.Tempo;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class GameActivity extends Activity {


	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	//setRequestedOrientation(Activity.SCREEN_ORIENTATION_LANDSCAPE);
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_game);
        setContentView(new GameView(this));
        
        /*
        
        //
        MidiTrack tempoTrack = new MidiTrack();
        MidiTrack noteTrack = new MidiTrack();

        // 2. Add events to the tracks
        // 2a. Track 0 is typically the tempo map

        Tempo t = new Tempo();
        t.setBpm(228);

        tempoTrack.insertEvent(t);

        // 2b. Track 1 will have some notes in it
        for(int i = 21; i < 108; i++) {

            int channel = 0, pitch = i, velocity = 100;
            NoteOn on = new NoteOn(i*480, channel, pitch, velocity);
            NoteOff off = new NoteOff(i*480 + 120, channel, pitch, 0);

            noteTrack.insertEvent(on);
            noteTrack.insertEvent(off);
        }

        // It's best not to manually insert EndOfTrack events; MidiTrack will
        // call closeTrack() on itself before writing itself to a file

        // 3. Create a MidiFile with the tracks we created
        ArrayList<MidiTrack> tracks = new ArrayList<MidiTrack>();
        tracks.add(tempoTrack);
        tracks.add(noteTrack);

        MidiFile midi = new MidiFile(MidiFile.DEFAULT_RESOLUTION, tracks);

        // 4. Write the MIDI data to a file
        
		// get a reference to the file.


        File output = new File(Environment.getExternalStorageDirectory() + "/sheets/example.mid");
        try {
            midi.writeToFile(output);
        } catch(IOException e) {
            Log.e(getClass().toString(), e.getMessage(), e);
        }
        
        
        try {
            player.setDataSource(output.getAbsolutePath());
            player.prepare();
        } catch (Exception e) {
            Log.e(getClass().toString(), e.getMessage(), e);
        }
        player.start();
        */
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_game, menu);
        return true;
    }
    
}
